/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "makecard_client_test.h"

#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "hilog_wrapper.h"
#include "makecard_srv_client.h"
#include "test_utils.h"

using namespace testing::ext;
using namespace SwanLink::Finance;
using namespace OHOS;
using namespace std;

namespace {
bool g_isMock = false;
}

void MakecardClientTest::SetUpTestCase(void)
{
    g_isMock = TestUtils::IsMock();
    GTEST_LOG_(INFO) << " g_isMock: " << g_isMock;
}

void MakecardClientTest::TearDownTestCase(void)
{
    g_isMock = false;
    TestUtils::ResetOnline();
}

void MakecardClientTest::SetUp(void)
{
}

void MakecardClientTest::TearDown(void)
{
}

namespace {

/**
 * @tc.name: MakecardClient001
 * @tc.desc: Test Makecard interface SetConfig
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient001, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient001 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        int configType = -1;
        int configValue = -1;

        auto ret = client.SetConfig(handle, configType, configValue);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient001 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        int configType = -1;
        int configValue = -1;

        auto ret = client.SetConfig(handle, configType, configValue);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient001 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient001 end.");
}
/**
 * @tc.name: MakecardClient002
 * @tc.desc: Test Makecard interface SetStandbyParam
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient002, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient002 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        int dir = -1;
        int pos = -1;
        int standbyTime = -1;

        auto ret = client.SetStandbyParam(handle, dir, pos, standbyTime);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient002 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        int dir = -1;
        int pos = -1;
        int standbyTime = -1;

        auto ret = client.SetStandbyParam(handle, dir, pos, standbyTime);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient002 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient002 end.");
}
/**
 * @tc.name: MakecardClient003
 * @tc.desc: Test Makecard interface PrintCard
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient003, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient003 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        BmpInfo cardBmpInfo = {};

        auto ret = client.PrintCard(handle, cardBmpInfo);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient003 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        BmpInfo cardBmpInfo = {};

        auto ret = client.PrintCard(handle, cardBmpInfo);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient003 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient003 end.");
}
/**
 * @tc.name: MakecardClient004
 * @tc.desc: Test Makecard interface GetDeviceInfo
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient004, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient004 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        int infoType = -1;
        char infoValue[128] = {0};

        auto ret = client.GetDeviceInfo(handle, infoType, infoValue);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient004 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        int infoType = -1;
        char infoValue[128] = {0};

        auto ret = client.GetDeviceInfo(handle, infoType, infoValue);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient004 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient004 end.");
}
/**
 * @tc.name: MakecardClient005
 * @tc.desc: Test Makecard interface GetErrorString
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient005, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient005 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        int status = -1;
        char statusDesc[128] = {0};

        auto ret = client.GetErrorString(handle, status, statusDesc);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient005 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        int status = -1;
        char statusDesc[128] = {0};

        auto ret = client.GetErrorString(handle, status, statusDesc);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient005 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient005 end.");
}
/**
 * @tc.name: MakecardClient006
 * @tc.desc: Test Makecard interface MoveCard
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient006, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient006 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        int postionMoveTo = -1;

        auto ret = client.MoveCard(handle, postionMoveTo);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient006 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        int postionMoveTo = -1;

        auto ret = client.MoveCard(handle, postionMoveTo);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient006 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient006 end.");
}
/**
 * @tc.name: MakecardClient007
 * @tc.desc: Test Makecard interface FlipCard
 * @tc.type: FUNC
 */
HWTEST_F(MakecardClientTest, MakecardClient007, TestSize.Level1)
{
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient007 start.");
    auto& client = MakecardSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;

        auto ret = client.FlipCard(handle);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient007 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;

        auto ret = client.FlipCard(handle);
        MAKECARD_HILOGI(MAKECARD_TEST, "MakecardClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "MakecardClient::MakecardClient007 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    MAKECARD_HILOGD(MAKECARD_TEST, "MakecardClient::MakecardClient007 end.");
}


}